<template>
  <t-dialog
    :header="`${header}-示范工程详情`"
    :visible.sync="visible"
    :onClose="closeDialog"
    :closeOnOverlayClick="false"
    :confirmBtn="null"
    width="80%"
    top="5%"
  >
    <t-tabs placement="left"  size="medium" v-model="stepValue">
      <t-tab-panel  value="1" label="申报详情">
        <t-sticky-tool
          :style="{ position: 'absolute', overflow: 'hidden',zIndex: 1000 }"
          :offset="[-40, -20]"
          @click="createPDF(1)"
        >
          <t-sticky-item  label="导出PDF" >
            <template #icon>
              <t-icon name="file-pdf"></t-icon>
            </template>
          </t-sticky-item>
        </t-sticky-tool>
        <project-detail :objId="objId"></project-detail>
      </t-tab-panel>
      <t-tab-panel  value="2" label="实施方案">
          <implement-plan-detail v-if="openSSFA" :project-id="objId"></implement-plan-detail>
          <div v-else style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待申报实施方案...</div>
      </t-tab-panel>
      <t-tab-panel  value="3" label="实施执行情况报告">
        <performance-report-list :projectId="objId"></performance-report-list>
      </t-tab-panel>
      <t-tab-panel  value="4" label="预验收">
        <pre-acceptance-detail v-if="openYYSSQ" :obj-id="objId"></pre-acceptance-detail>
        <div v-else style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待预验收申请...</div>
      </t-tab-panel>
       <t-tab-panel  value="5" label="验收申请">
        <acceptance-detail v-if="openYSSQ" :obj-id="objId"></acceptance-detail>
        <div v-else style="height: 100%;display: flex;justify-content: center;align-items: center;font-weight: bold;font-size: 50px;color: #ccc;">待验收申请...</div>
      </t-tab-panel>
    </t-tabs>
  </t-dialog>
</template>

<script>
import projectDetail from "./project-detail.vue";
import implementPlanDetail from "../../implement/components/implement-plan-detail.vue";
// import performanceReportDetail from "../../implement/components/performance-report-detail.vue";
import implementDetail from "../../implement/components/implement-detail.vue";
import performanceReportList from "../../implement/components/performance-report-list.vue";
import preAcceptanceDetail from "../../acceptance/components/pre-acceptance-detail.vue";
import AcceptanceDetail from "../../acceptance/components/acceptance-detail.vue";

export default {
  name: "project-detail-dialog",
  components:{
    projectDetail,
    implementDetail,
    implementPlanDetail,
    performanceReportList,
    preAcceptanceDetail,
    AcceptanceDetail
    // performanceReportDetail
  },
  props:{
    objId: [String,Number],
    header: String,
    tabDefaultValue: {
      type: String,
      default: '1'
    }
  },
  data(){
    return {
      visible: true,
      stepValue: this.tabDefaultValue,
      openSSFA: false,
      openSSBG: false,
      openYYSSQ: false,
      openYSSQ:false
    }
  },
  created() {
    this.checkSSFA();
    this.checkYYSSQ();
    this.checkYSSQ()
  },
  methods:{
    createPDF(type){
      const instance = this.$loading({
        fullscreen: true,
        attach: 'body',
        preventScrollThrough: false,
      });
      if(type===1){
        this.$api.kjsf.project.projectPDF(this.objId).then(response => {
          window.open(response.data.fullFilePath, '_blank')
          instance.hide();
        }).catch((e) => {
          instance.hide();
          this.$message.error(e.toString());
        });
      }else if(type===2){

      }else if(type===3){

      }

    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
    checkYYSSQ(){
      this.$api.kjsf.acceptance.preGetByProject(this.objId).then(response => {
        if(response.data){
          this.openYYSSQ = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkYSSQ(){
      this.$api.kjsf.acceptance.getByProject(this.objId).then(response => {
        if(response.data){
          this.openYSSQ = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    checkSSFA(){
      this.$api.kjsf.implement.projectEmbodimentGetByProjectId(this.objId).then(response => {
        if(response.data){
          this.openSSFA = true
        }
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style lang="less" scoped>
.t-tab-panel{
  padding: 10px;
  height: 65vh;
}
</style>
